package com.yanqu.road.server.cmd.activity.liondance;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LionDanceProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.liondance.LionDanceModule;
import com.yanqu.road.server.manger.activity.liondance.LionDanceMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_LION_DANCE_GIVE_FRIEND_BACK_FROM_CROSS, desc = "赠送返回")
public class LionDanceApplyHandleBackFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {

        LionDanceProto.CrossLionDanceApplyHandleRespMsg respMsg = LionDanceProto.CrossLionDanceApplyHandleRespMsg.parseFrom(yanQuMessage.getBytes());

        GamePlayer player = GamePlayerMgr.getOnlinePlayer(respMsg.getFromUserId());
        if(player == null){

            LionDanceMgr.getLogger().info("gift back player offline, playId : {}, cardId :{}, toUserId {} and applyNo {}, ret = {}", respMsg.getFromUserId(),
                    respMsg.getCardId(), respMsg.getToUserId(), respMsg.getApplyNo(), respMsg.getRet());

        }else {

            player.getModule(LionDanceModule.class).giveBackFromCross(respMsg.getRet(), respMsg.getToUserId(), respMsg.getCardId(), respMsg.getApplyNo());

        }

    }
}
